package Euler14;

public class Collatz {
	public static void main(String[] args) {
		int max = 0;
		int startingNum = 0;
		
		for(int i = 3; i < 1000000; i++)
		{
			int count = 1;
			long n = i;
			
			while(n>1)
			{
				if(n%2==0)
				{
					n = getEven(n);
				}
				else
				{
					n = getOdd(n);
				}
				count++;
			}
			
			if(count>max)
			{
				max = count;
				startingNum = i;
			}
			
			//System.out.println("Number is: " + i + ", and there are " + count + " steps.");
		}
		
		System.out.println("Number is: " + startingNum + ", and there are " + max + " steps.");
	}
	
	static long getOdd(long n)
	{
		return ((3*n)+1);
	}
	
	static long getEven(long n)
	{
		return n/2;
	}
}